<?php
use yii\helpers\Url;

$web = Url::to('@web');

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>ECharts</title>
  <!-- 引入 echarts.js -->
  <script src="<?= $web ?>/js/echarts.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="width: 600px;height:400px;"></div>
<div id="pie" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
  // 基于准备好的dom，初始化echarts实例
  var myChart = echarts.init(document.getElementById('main'));
  var chartseri=[];
  var chartdata=[];
  var chartdata1=[];
  var chartdata2=[];
  var chartPie=[];
  re=<?= $result ?>;

  for(var i = 0; i < re.length; i++){
    var piedata={};
    var bardata={};
    chartseri[i]=re[i]['walfare_name'];
    chartdata1[i]=re[i]['num'];
    chartdata2[i]=re[i]['integral'];
    piedata.value=re[i]['integral'];
    piedata.name=re[i]['walfare_name'];
    chartPie[i]=piedata;
  }
  // var chartdata=[70, 20, 36, 10, 10, 20];

  // 指定图表的配置项和数据
  var option = {
    title: {
      text: '福利人数统计'
    },
    tooltip: {},
    legend: {
      data:['福利人数','福利分数']
    },
    xAxis: {
      data: chartseri
    },
    yAxis: {},
    series: [{
      name: '福利人数',
      type: 'bar',
      data: chartdata1
    },{
      name: '福利分数',
      type: 'bar',
      data: chartdata2
    }
    ]
  };

  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);

  var myPie = echarts.init(document.getElementById('pie'));
  option1 = {
    title : {
      text: '各类型福利占比',
      subtext: '纯属虚构',
      x:'center'
    },
    tooltip : {
      trigger: 'item',
      formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
      orient: 'vertical',
      left: 'left',
      data: chartseri
    },
    series : [
      {
        name: '访问来源',
        type: 'pie',
        radius : '55%',
        center: ['50%', '60%'],
        data:chartPie,
        itemStyle: {
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };

  myPie.setOption(option1);

</script>
</body>
</html>